//
//  main.swift
//  NEW
//
//  Created by huanglei on 2017/9/11.
//  Copyright © 2017年 huanglei15. All rights reserved.
//

import Foundation
struct Student{
    var name:String
    var mathScore:Float
    var englishScore:Float
    var average:Float
    
    
    init(name:String,mathScore:Float,englishScore:Float) {
        self.name = name
        self.mathScore = mathScore
        self.englishScore = englishScore
        self.average = Float(self.mathScore + self.englishScore) / 2
    }
}
func count(students:[Student]) -> [Student] {
    var result = students
    for i in 0...result.count-2 {
        for j in i+1...result.count-1{
            if(result[i].average > result[j].average){
                let tmp = result[i]
                result[i] = result[j]
                result[j] = tmp
            }
        }
    }
    return result
}


var student01 = Student(name: "赵二", mathScore: 67, englishScore: 95)
var student02 = Student(name: "王五", mathScore: 87, englishScore: 51)
var student03 = Student(name: "小红", mathScore: 67, englishScore: 86)
var student04 = Student(name: "张三", mathScore: 77, englishScore: 88)
var student05 = Student(name: "李四", mathScore: 95, englishScore: 97)
var student06 = Student(name: "小黄", mathScore: 85, englishScore: 84)
var student07 = Student(name: "小白", mathScore: 82, englishScore: 76)
var student08 = Student(name: "小花", mathScore: 93, englishScore: 66)
var student09 = Student(name: "小明", mathScore: 63, englishScore: 93)
var student10 = Student(name: "三毛", mathScore: 89, englishScore: 92)

var result = count(students: [       student01,
                                     student02,
                                     student03,
                                     student04,
                                     student05,
                                     student06,
                                     student07,
                                     student08,
                                     student09,
                                     student10])

print(" 英语和数学平均分的成绩从小到大排列为: ")

for i in 0..<result.count{
    print("姓名:\(result[i].name),数学成绩:\(result[i].mathScore),英语成绩:\(result[i].englishScore),平均分:\(result[i].average)")
}





